//
//  DBJDoctorApplyTableViewController.m
//  DBJ
//
//  Created by 花化华 on 2016/11/12.
//  Copyright © 2016年 itcast. All rights reserved.
//
#define DOCCELL @"docCell"
#import "DBJDoctorApplyTableViewController.h"
#import "DBJDoctorListCell.h"
#import <MJRefresh.h>
#import "DBJDoctorListModel.h"

@interface DBJDoctorApplyTableViewController ()

@property(strong,nonatomic)NSArray<DBJDoctorListModel *> *DocList;

@end

@implementation DBJDoctorApplyTableViewController

-(NSArray *)DocList{
    if (_DocList == nil) {
        _DocList = [NSArray array];
    }
    return _DocList;
}

- (void)dbjSetupSubviews{
    [super dbjSetupSubviews];
    
        /*------------*1. 搭建UI *-------------*/
    //注册cell
    UINib *nib = [UINib nibWithNibName:@"DBJDoctorListCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:DOCCELL];
    
    //设置行高
    self.tableView.rowHeight = 80;
    
        /*------------*2. 设置上下拉刷新 *-------------*/
    //解决循环引用问题
    __weak typeof(self) weakSelf = self;
    //下拉刷新
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
    //刷新指定时间
    [NSThread sleepForTimeInterval:2.0];
    [weakSelf.tableView.mj_header endRefreshing];
    }];
    //上拉刷新
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //刷新指定时间
        [NSThread sleepForTimeInterval:2.0];
        [weakSelf.tableView.mj_footer endRefreshing];
    }];
    
        /*------------* 获取网络数据 *-------------*/
    NSString *url = @"http://iosapi.itcast.cn/doctor/matchDoctors.json.php";
    NSDictionary *parameter = @{@"ci1_id":@1,@"ci2_id":@3,@"ci3_id":@3,@"diagnosis_type":@0,@"page_size":@15,@"is_confirmed":@1,@"user_id":@1000089, @"page":@1,@"has_diagnosis":@2};
    [DBJDoctorListModel getDoctorListDataWithURLString:url andParameters:parameter andSuccessBlock:^(NSArray *newsList) {
        //获取下载并解析之后的模型数组
        self.DocList = newsList;
        //刷新
        [self.tableView reloadData];
    } andErrorBlock:^(NSError *error) {
        //打印错误
        NSLog(@"error = %@",error);
    }];
}

- (void)dbjSetupNavigationItems{
    [super dbjSetupNavigationItems];
}

#pragma mark - 数据源方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.DocList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //1.创建cell
    DBJDoctorListCell *cell = [tableView dequeueReusableCellWithIdentifier:DOCCELL forIndexPath:indexPath];
    //2.给cell赋值
    cell.docModel = self.DocList[indexPath.row];
    //3.返回cell
    return cell;
}

@end
